README: Soil Warming Experiment — Data & R Scripts
==================================================

Overview
--------
This project contains chamber/chamber+Bayesian analyses and a separate tower-flux
(gap-filling & uncertainty) pipeline. All code is in R.

Requirements
------------
- R >= 4.2
- Suggested packages (install as needed):
  tidyverse, readr, dplyr, lubridate, ggplot2, rjags, coda,
  data.table, here, patchwork, readxl, writexl, janitor,
  REddyProc (for tower data), zoo
- Set the working directory to the project root, e.g.:
  setwd("/path/to/project")

Project Structure (key items)
-----------------------------
- Root (this folder): chamber/chamber+Bayesian scripts and most data files
- golden/ : tower workflow (gap-filling, uncertainty, manuscript plots)

Data Files (root unless noted)
------------------------------
- Chamber/ancillary: co2flux.csv, ch4flux.csv, co2flux_gpp.csv, fluxes5.csv
- N2O: db_gutavita_N2O_all.csv / .xlsx, n2osummary.csv
- DOC: DOC transport.csv / .xlsx, summary_DOC.csv
- Water table & hydrology: WaterTable.csv, wtd_martos_21_25.csv, Compilado_ST2.csv
- Tower aux: tower_var.csv
- Cumulative/seasonal: NEEcum.xlsx, St1NEEcum.csv, ST1NEEcum2.csv, St2NEEcum.csv, St2NEE_MC.csv, StN1EE_MC.csv
- Summaries (generated): Summary_*.csv/.rds, PerGas_CO2_CH4_with_CO2eq_Mg_ha_mean95CI.*, Totals_CO2eq_*.csv
- Predicted/model intermediates: *.rds, *_30min_*.csv/.rds, *_pred_30min_*.csv/.rds
- Figures: figure.png, figure_transparent.png, figure.svg, Rplots.pdf

Chamber + Bayesian Workflow (root)
----------------------------------
Run from the project root. Quotes are used where filenames contain spaces.

Step 1 — Prepare & clean data
  Rscript flux_chamber3.r
  Rscript flux_wt_guatavita_jc.r
  Rscript waterlevel.r

Step 2 — Build prediction datasets (MUST come before Bayesian)
  Rscript "flux predict.R"
  Rscript "flux predict2.R"

Step 3 — Bayesian flux partitioning (NEE → GPP + ER)
  IMPORTANT: Run separately for each station by setting/replacing the
  station code (ST1, then ST2) inside the scripts or via arguments if applicable.
  Rscript "bayesian models.r"
  Rscript bayesianflux.r
  # Example guidance (inside the scripts):
  #   station <- "ST1"  # then rerun with station <- "ST2"

Step 4 — Trace gases
  Rscript DOC_flux.r
  Rscript N2Oflux.r

Step 5 — Final figures & summaries
  Rscript "final plot.r"

Primary Outputs (root)
----------------------
- *_Model_EC_long.csv/.rds
- *_pred_30min_*.csv/.rds
- Final_Cumulative_CO2_CH4_CO2eq_2023_2024_bySeason_Method_Station.csv/.rds
- Summary_CO2_CH4_CO2eq_byMethod_Station_Season_Year.csv/.rds
- Summary_TOTAL_CO2eq_byMethod_Station_Season_Year.csv
- PerGas_CO2_CH4_with_CO2eq_Mg_ha_mean95CI.csv/.xlsx
- Totals_CO2eq_across_gases_Mg_ha_mean95CI.csv
- season_mean_variance_CO2_CH4_2023_2024.csv
- Figures: figure.png, figure_transparent.png, figure.svg

Tower Workflow (golden/ folder)
-------------------------------
Location: ./golden
Files:
  - REddyProc_Guatavita_Station1_Gold.R
  - REddyProc_Guatavita_Station2_Gold.R
  - Guatavita_gapfilling_uncertainty.R
  - Guatavita_plot_manuscript.R

Order of execution:
  1) Gap-filling per station (REddyProc)
     Rscript golden/REddyProc_Guatavita_Station1_Gold.R
     Rscript golden/REddyProc_Guatavita_Station2_Gold.R

  2) Uncertainty analysis & compilation
     Rscript golden/Guatavita_gapfilling_uncertainty.R

  3) Manuscript-quality plots
     Rscript golden/Guatavita_plot_manuscript.R

Notes for Tower pipeline:
  - Requires REddyProc package (install.packages("REddyProc")) and typical
    met/flux variable columns (e.g., NEE, USTAR, Rg, Tair, VPD, etc.).
  - Ensure input CSVs for each station are in the locations the scripts expect.
  - Station-specific settings are inside the REddyProc_* scripts.

Reproducibility & Tips
----------------------
- Keep relative paths; run from project root.
- For Bayesian runs, set a fixed random seed inside the scripts for reproducibility.
- Large *.rds files are intermediates; do not delete unless you intend to re-run models.
- If running on a fresh machine, install packages first, then follow the workflow.

Contact
-------
Juan C. Benavides — Pontificia Universidad Javeriana
